<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件通信-自定义事件-子组件给父组件传递数据</title>
    <script src="https://cdn.staticfile.org/vue/2.6.11/vue.js"></script>
</head>
<body>
<div id="case13-demo6">
    <h3>组件:{{subName}}</h3>
    <child-component v-on:change="handleName"></child-component>
</div>
<script type="text/javascript">
    var case13Demo6 = new Vue({
        el: "#case13-demo6",
        data: {
            subName: "slsher"
        },
        methods: {
            handleName: function (value) {
                this.subName = value
            }
        },
        components: {
            'child-component': {
                template:
                `
                <div>
                    <button v-on:click="handleChange">更换组件名称</button>
                    <button v-on:click="handleChange1">更换组件名称</button>
                </div>

                `,
                methods: {
                    handleChange:function () {
                        this.$emit('change','slsher1')
                    },
                    handleChange1:function () {
                        this.$emit('change','slsher2')
                    }
                }
            }
        }
    })
</script>
</body>
</html>